package mest.service.Modeling;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import mest.util.ResultObj;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import mest.dao.Modeling.AccountFileDao;
import mest.entity.AccountFile;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Twinson Wong
 * @Title AccountFileService.java
 * @description 账户档案
 * @time 2019年12月16日 下午11:23:25
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class AccountFileService {
    @Resource
    AccountFileDao accountFileDao;

    public List<AccountFile> selectAll(Map<String, Object> map) {
        return accountFileDao.selectAll(map);
    }

    public int count(Map<String, Object> map) {
        return accountFileDao.count(map);
    }

    public ResultObj insert(Map<String, Object> map) {
        try {
            accountFileDao.insert(map);
            return ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                return ResultObj.createErrorMsg("数据已存在");
            }
            return ResultObj.createErrorMsg(ResultObj.ERROR);
        }
    }

    public ResultObj update(Map<String, Object> map) {
        try {
            accountFileDao.update(map);
            return ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                return ResultObj.createErrorMsg("数据已存在");
            }
            return ResultObj.createErrorMsg(ResultObj.ERROR);
        }
    }

    public int delete(Map<String, Object> map) {
        return accountFileDao.delete(map);
    }


    public AccountFile selectById(Integer id, String theirDb) {
        return accountFileDao.selectById(id, theirDb);
    }

    public Integer updateMoney(Integer id, BigDecimal balance, String theirDb) {
        return accountFileDao.updateMoney(id, balance, theirDb);
    }

}
